package com.bensonbasement.snorflux.server.events;

import java.util.HashSet;
import java.util.Set;

import com.bensonbasement.snorflux.messages.fromserver.reports.Report;
import com.bensonbasement.snorflux.messages.fromserver.reports.WalkReport;
import com.bensonbasement.snorflux.server.world.Actor;
import com.bensonbasement.snorflux.server.world.IViewer;
import com.bensonbasement.snorflux.server.world.Level;
import com.bensonbasement.snorflux.server.world.Space;
import com.bensonbasement.snorflux.utils.Direction;
import com.bensonbasement.snorflux.utils.SpaceReference;

public class WalkEvent extends Event {
	
	private final Actor actor;
	private final Space origin;
	private final Space destination;
	private final Direction walkDirection;
	
	public WalkEvent(Actor actor, Space origin, Direction walkDirection) {
		this.actor = actor;
		this.origin = origin;
		this.destination = origin.getNeighbor(walkDirection);
		this.walkDirection = walkDirection;
	}
	
	@Override
	public Report render(IViewer viewer) {
		if (viewer.canSeeSpace(origin) || 
				viewer.canSeeSpace(destination)) {
			WalkReport report = new WalkReport(actor.getGlyph(),actor.getWorldElementID(),origin.getReference(),walkDirection);
			return report;
		}
		else {
			return null;
		}
	}
	
	@Override
	public Set<Level> getRelevantLevels() {
		HashSet<Level> retVal = new HashSet<Level>();
		retVal.add(actor.getLevel());
		return retVal;
	}
}
